/**
 * Created by Administrator on 2017/11/11.
 */
const mongoose = require('mongoose');
const shortid = require('shortid');
const moment = require('moment');


const FollowSchema = new mongoose.Schema({
    _id: {
        type: String,
        default: shortid.generate,
        unique: true//主键
    },
    store_id:{
        type:String,
        ref:'Seller'
    },
    king_id:{
        type:String,
        ref:'Buller'
    }


})


FollowSchema.statics = {
    getFollowById: (id,king_id, callback) => {
        Follow.findOne({'store_id': id,'king_id':king_id}).then(function (store) {
            callback(null, store);
        }).catch(function (err) {
            callback(err);
        })
    },
    getFollowsByKing:(id,callback)=>{
        Follow.find({'king_id': id}).populate('store_id').then(function (stores) {
            callback(null, stores);
        }).catch(function (err) {
            callback(err);
        })
    }

}

const Follow = mongoose.model('follow', FollowSchema);
module.exports = Follow;
